<?php
// +----------------------------------------------------------------------
// | OneKeyAdmin [ Believe that you can do better ]
// +----------------------------------------------------------------------
// | Copyright (c) 2020-2023 http://onekeyadmin.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: MUKE <513038996@qq.com>
// +----------------------------------------------------------------------
namespace plugins\userrecharge\admin\model;

use think\Model;
use app\admin\model\User;

class UserRecharge extends Model
{
    // 关联用户
    public function user()
    {
        return $this->hasOne(User::class, 'id', 'user_id')->bind([
            'user_mobile' => 'mobile',
            'user_email'  => 'email',
            'user_cover'  => 'cover',
        ]);
    }

    // 搜索器
    public function searchDateAttr($query, $value, $array)
    {
        if (! empty($value)) { 
            $query->whereBetweenTime('create_time', $value[0], $value[1]);
        }
    }
    
    public function searchKeywordAttr($query, $value, $array)
    {
        if ($value !== '') { 
            $query->where('user_id|id', 'like' , '%' . $value . '%');
        }
    }

    public function searchStatusAttr($query, $value, $array)
    {
        if (! empty($value)) { 
            $query->where('status', $value);
        }
    }

    public function getCStatusAttr($value, $array)
    {
        switch ($array['status']) {
            
            case 1:
                return '待支付';
                break;
            case 2:
                return '已支付';
                break;
            case 3:
                return '已完成';
                break;
            case 4:
                return '已失效';
                break;    
        }
    }

    public function getMethodAttr($value, $array)
    {
        switch ($array['pay_method']) {
            case 0:
                return '支付宝';
                break;
            case 1:
                return '微信';
                break;
        }
    }
}